﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EMK.Cartography;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using Microsoft.Xna.Framework;
using EMK.LightGeometry;
using GameLib;
using DustObjects;

namespace DustObjects {
    public class Board : GraphBoard {
        public Graph _graph;

        public Board(string graphFile) {
            Stream streamRead = File.Open(AppDomain.CurrentDomain.BaseDirectory + graphFile, FileMode.Open);
            BinaryFormatter binaryRead = new BinaryFormatter();
            base.G = (Graph)binaryRead.Deserialize(streamRead);
            streamRead.Close();

            foreach (DustNode node in base.G.Nodes) {
                node.Units = new Units();
            }
        }

        public DustNode ClosestNode(Vector2 position) {
            return ClosestNode(position.X, position.Y);
        }
        public DustNode ClosestNode(double x, double y) {
            double distance = 0;
            Node node = (Node)_graph.ClosestNode(x, y, 0, out distance, true);
            return (DustNode)node;
        }
    }
}
